﻿using GameFramework.Event;
using System;
using TowerDefence_Zombie.Data;

namespace TowerDefence_Zombie
{
    public class GuideCondition_Level : GuideCondition_Base
    {
        private int targetLevel;

        public GuideCondition_Level(DRGuideCondition conditionInfo, Action conitionCompleteClick)
            : base(conditionInfo, conitionCompleteClick)
        {
            targetLevel = conditionInfo.ConditionParams_Int;
        }

        public override void StartCondition()
        {
            base.StartCondition();
            GameEntry.Event.Subscribe(LevelSuccessEventArgs.EventId, OnLevelSuccess);
            if (GameEntry.Data.GetData<DataPlayer>().GetCurBattleLevel() >= targetLevel)
            {
                IsCompleteFlag = true;
            }
        }

        private void OnLevelSuccess(object sender, GameEventArgs e)
        {
            LevelSuccessEventArgs ne = (LevelSuccessEventArgs)e;
            if (ne == null)
                return;

            if (ne.Level >= targetLevel)
            {
                IsCompleteFlag = true;
            }
        }

        public override void Dispose()
        {
            GameEntry.Event.Unsubscribe(LevelSuccessEventArgs.EventId, OnLevelSuccess);
            base.Dispose();
        }
    }
}
